<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\BaseModel;
use App\Models\DeviceInfo;

class ApiH5Controller extends BaseController
{
	private $_user_model;

    private $_model;

	public function __construct(){
        $this->_user_model = new BaseModel('admin_users');
        $this->_model = new DeviceInfo();
    }

	// 全部控制
    public function login_m(Request $r) {
        $uname = $r->uname;
        $pwd = $r->pwd;
        $_info = $this->_user_model->getOne(['username'=>$uname], ['id', 'password']);
        if(!empty($_info) && password_verify($pwd, $_info['password'])) {
        	//记录登录 状态
        	$arr = [
	            'uname' =>$_info['id'],
	            'addtime'=>time(),
	        ];
        	session_start();
            $_SESSION['user'] = $arr;
			echo 1;
        } else {
        	echo 0;
        }
    }
    // 全部控制
    public function index_m(Request $r) {
        echo json_encode([
			'code'=>'200',
			'msg'=>'成功',
		]);
    }

    public function oneon_m(Request $r) {
        $_infos = $this->_model->getall(['enable'=>1], ['id', 'name', 'code', 'cmd', 'status', 'type']);

        foreach ($_infos as $info) {
          echo $value."<br/>";
        }
    }


}